/**
 * jaroverlay-maven-plugin : add remove replace content and repackage nested archives
 * 
 * Copyright (C) 2008  Paul Merlin
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.n0pe.mojo.examples.war;


import java.io.IOException;
import java.io.PrintWriter;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.n0pe.mojo.examples.ExampleLocal;


/**
 * @author Paul Merlin <eskatos@n0pe.org>
 */
public class ExampleServlet
        extends HttpServlet {


    private static final long serialVersionUID = 1L;


    @EJB
    private ExampleLocal exampleEjb;


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet ExampleServlet</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet ExampleServlet at " + request.getContextPath() + "</h1>");
            out.println(
                    "<p>This is the <a href=\"http://code.google.com/p/jaroverlay-maven-plugin/\">jaroverlay-maven-plugin</a> exemple</p>");
            out.println("<p><img src=\"logo.png\"/></p>");
            out.println("<p>RandomString from EJB: " + exampleEjb.getRandomString(16) + "</p>");
            out.println("<p>This one will be removed: <img src=\"tag.png\"/></p>");
            out.println("</body>");
            out.println("</html>");
        } finally {
            out.close();
        }
    }


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.sendError(response.SC_FORBIDDEN);
    }


}
